/**
 * 神州信息(2012)
 */
package net.abbp.report.view.cell.editor.eform;

import java.awt.Component;

import javax.swing.SwingUtilities;

import net.abbp.engine.ui.model.component.Select;
import net.abbp.report.model.Cell;
import net.abbp.report.view.cell.editor.AbstractCellEditor;
import net.abbp.report.view.grid.Grid;

import com.reportgear.core.swing.pane.base.EditorPane;
import com.reportgear.core.swing.pane.base.JBaseDialog;

/**
 * 下拉框编辑器
 * 
 * @version 1.0
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since ABBP 1.0
 * 
 *        <pre>
 * 历史：
 *      建立: Aug 1, 2012 lexloo
 * </pre>
 */
public class SelectEditor extends AbstractCellEditor {
    private Select select;

    @Override
    public Component getCellEditorComponent(Grid grid, Cell cell) {
        SelectEditPane editorPane = new SelectEditPane();

        editorPane.populate((Select) cell.getValue());

        if (editorPane.showDialog(grid) == JBaseDialog.RESULT_OK) {
            this.select = editorPane.update();
        }

        return null;
    }

    @Override
    public Object getCellEditorValue() {
        return this.select;
    }

    private static class SelectEditPane extends EditorPane<Select> {
        private static final long serialVersionUID = 4643550630404842665L;
        private Select value;

        public SelectEditPane() {
        }

        @Override
        public void populate(Select value) {
            this.value = value;
        }

        @Override
        public Select update() {

            return this.value;
        }

        @Override
        public int showDialog(Component owner) {
            return this.showDialog(SwingUtilities.getWindowAncestor(owner), "下拉选择", 300, 120);
        }
    }

}
